<template>
    <div class="dialog">
        <el-dialog :title="dialog.title" :visible.sync="dialog.show" :close-on-click-modal='false' :close-on-press-escape='false'
            :modal-append-to-body="false">
            <div class="form">
                <el-form ref="form" :model="formData" :rules="form_rules" label-width="120px" 
                    style="margin:10px;width:auto">
                    <!-- <el-form-item label="管理员ID" prop="Aid">
                        <el-input type="content" v-model="formData.Aid"></el-input>
                    </el-form-item> -->
                    <el-form-item label="用户昵称" prop="AdminName">
                        <el-input type="content" v-model="formData.AdminName"></el-input>
                    </el-form-item>
                    <el-form-item label="用户账号" prop="AdminPsw">
                        <el-input type="content" v-model="formData.AdminPsw"></el-input>
                    </el-form-item>
                    <el-form-item label="用户密码" prop="AdminAccount">
                        <el-input type="content" v-model="formData.AdminAccount"></el-input>
                    </el-form-item>
                    <el-form-item label="用户年龄" prop="AdPhone">
                        <el-input type="content" v-model="formData.AdPhone"></el-input>
                    </el-form-item>
                    <el-form-item label="用户激活状态" prop="AdStatus">
                        <el-input type="content" v-model="formData.AdStatus"></el-input>
                    </el-form-item>
                    <el-form-item class="text_right">
                        <el-button @click="dialog.show=false">取消</el-button>
                        <el-button type="primary" @click="onSubmit('form')">提交</el-button>
                    </el-form-item>
                </el-form>

            </div>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                form_rules: {
                    // Aid: [
                    //     { required: true, message: '用户ID不能为空', trigger: 'blur' }
                    // ],
                    AdminName: [
                        { required: true, message: '用户昵称不能为空', trigger: 'blur' }
                    ],
                    AdminPsw: [
                        { required: true, message: '用户账号不能为空', trigger: 'blur' }
                    ],
                    AdminAccount: [
                        { required: true, message: '用户密码不能为空', trigger: 'blur' }
                    ],
                    AdPhone: [
                        { required: true, message: '用户年龄不能为空', trigger: 'blur' }
                    ],
                    AdStatus: [
                        { required: true, message: '用户激活状态不能为空', trigger: 'blur' }
                    ]
                }
            }
        },
        props: {
            dialog: Object,
            formData: Object
        },
        mounted(){
             
        },
        methods: {

            onSubmit(form) {

                this.$refs[form].validate(valid => {
                    if (valid) { 
                        const url=this.dialog.option=="add" ? "add" : "edit";
                         this.axios({
                             method: 'post',
                             url: `http://127.0.0.1:3000/api/admin/${url}`,
                            data: {
                                Aid:this.formData.Aid,
                                AdminName:this.formData.AdminName,
                                AdminPsw:this.formData.AdminPsw,
                                AdminAccount:this.formData.AdminAccount,
                                AdPhone:this.formData.AdPhone,
                                AdStatus:this.formData.AdStatus,
                            }
                        })
                            .then(res => {
                                this.$message({
                                    message: '成功',
                                    type: 'success',
                                })
                                this.dialog.show = false;
                                console.log(this.formData);
                                this.$router.go(0);
                            })
                            .catch(err =>{
                                console.log(err)
                            })

                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>